<?php

namespace App\Console\Commands;

use App\Models\ScreenCustomerTemp;
use Carbon\Carbon;
use Illuminate\Console\Command;

class IncrementScreenTempTable extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'increment:screen_temp';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '大屏数据临时修改';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $bench = new \Ubench();
        $bench->start();

        $count = ScreenCustomerTemp::query()->where('customer_short_name', '中创新航')->count();
        $needCount = 1199;
        if ($count >= $needCount) {
            return 0;
        }
        for ($i = 0; $i < ($needCount - $count); $i++) {
            $itemData = [
                'customer_number' => 'JF/20048',
                'customer_name' => '中创新航',
                'customer_short_name' => '中创新航',
                'product_name' => '转轮除湿机组',
                'product_model' => 'JFL-23350DE',
                'product_date' => Carbon::parse('2020-12-05')->addDays($i)->toDateString()
            ];
            $screenCustomerTemp = new ScreenCustomerTemp();
            $screenCustomerTemp->fill($itemData);
            $screenCustomerTemp->saveOrFail();
        }

        $bench->end();
    }
}
